package cn.zhuizikejithreeig.com.myapplication;

import android.os.Handler;
import android.os.Looper;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.listener.OnItemSelectedListener;
import com.contrarywind.view.WheelView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private WheelView mWheelView;
    private int i = 1;
    private Handler handler = new Handler(Looper.getMainLooper());
    private TextView mTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //设置波轮滚动

        mWheelView = (WheelView) findViewById(R.id.wheelview);
       mTextView= (TextView) findViewById(R.id.text);
        mWheelView.setCyclic(false);
        final List<String> mOptionsItems = new ArrayList<>();
        mOptionsItems.add("item0");
        mOptionsItems.add("item1");
        mOptionsItems.add("item2");

        mWheelView.setAdapter(new ArrayWheelAdapter(mOptionsItems));
        mWheelView.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                Toast.makeText(MainActivity.this, "" + mOptionsItems.get(index), Toast.LENGTH_SHORT).show();
            }
        });

    }

    private int postion = 1;
    public void button(View view) {

        if (i%2==0){
            mWheelView.setVisibility(View.GONE);
            System.out.println("隐藏了");
        }else {
            mWheelView.setVisibility(View.VISIBLE);
            System.out.println("显示了");

        }

        handler.post(new Runnable() {
            @Override
            public void run() {


                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mTextView.setText("这是"+postion);
                    }
                });
                postion++;
                handler.postDelayed(this, 1000);

            }
        });
    }
}
